home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / ucrasm27.zip / SOURCE.ZIP / ARGC.ASM < prev    next >
Assembly Source File  |  1991-10-23  |  2KB  |  83 lines

  1. ;
  2.         extrn    PSP:word
  3. ;
  4. StdGrp        group    stdlib,stddata
  5. stddata        segment    para public 'sldata'
  6. stddata        ends
  7. ;
  8. stdlib        segment    para public 'slcode'
  9.         assume    cs:stdgrp
  10. ;
  11. ;
  12. ; Argc-        Counts the number of command line arguments
  13. ;
  14. ; inputs:
  15. ;
  16. ; Global variable PSP must hold the current program segment prefix.
  17. ;
  18. ; Outputs:
  19. ;
  20. ;    CX-    Contains the number of command line arguments.
  21. ;
  22. ;
  23. cr        equ    13
  24. ;
  25. ;
  26.         public    sl_Argc
  27. ;
  28. sl_Argc        proc    far
  29.         push    ds
  30.         push    di
  31.         push    ax
  32. ;
  33.         mov    di, seg    PSP
  34.         mov    ds, di
  35.         mov    ds, ds:PSP
  36. ;
  37.         mov    di, 80h            ;Pointer to start of cmd line-1
  38.         mov    cx, 0            ;Start cnt at zero
  39. CntLoop:    inc    di            ;Move on to next char.
  40.         cmp    byte ptr [di], ' '    ;Skip all spaces here.
  41.         je    CntLoop
  42.         mov    al, [di]
  43.         cmp    al, cr            ;See if carriage return
  44.         je    ArgcDone
  45. ;
  46. ; We just headed into a word of some sort. Skip all the chars in this argument.
  47. ;
  48.         inc    cx            ;First, count this argument
  49. ;
  50.         cmp    al, '"'            ;See if it's a string.
  51.         je    GotString
  52.         cmp    al, "'"
  53.         je    GotString
  54. ;
  55. ; If not a string, skip to next space or CR.
  56. ;
  57. SkipWord:    inc    di
  58.         cmp    byte ptr [di], ' '
  59.         je    CntLoop
  60.         cmp    byte ptr [di], cr
  61.         je    ArgcDone
  62.         jmp    skipWord
  63. ;
  64. ; If we've got a string, skip to the delimiter or to the end of the line.
  65. ;
  66. GotString:    inc    di
  67.         cmp    al, [di]        ;See if the delimiter
  68.         je    CntLoop
  69.         cmp    byte ptr [di], cr    ;See if EOLN
  70.         jne    GotString
  71. ;
  72. ; Come down here when we're done:
  73. ;
  74. ArgcDone:    pop    ax
  75.         pop    di
  76.         pop    ds
  77.         ret
  78. sl_Argc        endp
  79. ;
  80. ;
  81. stdlib        ends
  82.         end
  83.